<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <input v-model="addMsg" type="text">
        <button @click="add">添加</button>
        <input type="text">
        <button>查询</button>
        <ul>
            <li v-for="(item,index) in arr">{{item.msg}}<button @click="remove(item)">delete</button></li>
        </ul>
    </div>
</body>
<script src="./js/vue.js"></script>
<script>
    var app = new Vue({
        el: '#app',
        data: {
            addMsg: '',
            arr: []
        },
        methods: {
            add() {
                this.arr.push({
                    id: new Date().getTime(),
                    msg: this.addMsg
                })
                this.addMsg = ''
            },
            remove(data) {
                console.log(data)
                var index = this.arr.findIndex(item => {
                    return item.id === data.id
                })
                this.arr.splice(index, 1)
                console.log('index', index)
            }
        },
        computed: {

        }
    })
</script>

</html>